﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ClaimSpecification", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(ClaimSpecification))]
    public class ClaimSpecificationSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IClaimSpecification clazz;
        
        public ClaimSpecificationSerializer(IClaimSpecification clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("CalculationPeriod");
            if (clazz.CalculationPeriod!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "CalculationPeriod");
                Writer.WriteString(clazz.CalculationPeriod.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : CalculationPeriod");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("InterestRate");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.InterestRate))).ToString());
            Writer.WriteEndElement();
            if (clazz.CalculationBeginning!=null) {
                Writer.WriteStartElement("CalculationBeginning");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.CalculationBeginning))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.CalculationEnd!=null) {
                Writer.WriteStartElement("CalculationEnd");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.CalculationEnd))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="CalculationPeriod") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimSpecification>CalculationPeriod");
                }
                clazz.CalculationPeriod = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.CalculationPeriod(Reader.ReadElementString("CalculationPeriod"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimSpecification>CalculationPeriod", Reader.LocalName);
            }
            if (Reader.LocalName=="InterestRate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimSpecification>InterestRate");
                }
                clazz.InterestRate = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("InterestRate")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimSpecification>InterestRate", Reader.LocalName);
            }
            if (Reader.LocalName=="CalculationBeginning") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimSpecification>CalculationBeginning");
                }
                clazz.CalculationBeginning = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("CalculationBeginning")).Value;
            }
            if (Reader.LocalName=="CalculationEnd") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimSpecification>CalculationEnd");
                }
                clazz.CalculationEnd = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("CalculationEnd")).Value;
            }
        }
    }
}
